package com.kgc.service.impl;

import com.kgc.dto.MalfunctionDto;
import com.kgc.dto.MalfunctionOptionsDto;
import com.kgc.mapper.MalfunctionOptionsMapper;
import com.kgc.service.MalfunctionOptionsService;
import com.kgc.service.MalfunctionService;
import com.kgc.pojo.Malfunction;
import com.kgc.mapper.MalfunctionMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 故障 服务实现类
 * </p>
 *
 * @author zsy
 * @since 2021-08-04
 */
@Service
public class MalfunctionServiceImpl extends ServiceImpl<MalfunctionMapper, Malfunction> implements MalfunctionService {
    //故障
    @Autowired
    private MalfunctionMapper malfunctionMapper;
    //故障字典
    @Autowired
    private MalfunctionOptionsMapper malfunctionOptionsMapper;

    @Override
    public List<MalfunctionDto> findSpecListByModelId(Long modelId) {
        List<MalfunctionDto> malfunctionList = malfunctionMapper.findSpecListByModelId(modelId);
        if (malfunctionList != null){
            for (MalfunctionDto malfunctionDto : malfunctionList) {
                Long id = malfunctionDto.getId();
                List<MalfunctionOptionsDto> malfunctionOptionsDtos = malfunctionOptionsMapper.getMfosByModelIdAndMalfId(id);
                malfunctionDto.setOptionsList(malfunctionOptionsDtos);
            }
        }
        return malfunctionList;
    }
}
